package com.eugene.process;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eugene.dao.MarketVariableDAO;
import com.eugene.dao.ScenarioDAO;
import com.eugene.element.FnCalendar;
import com.eugene.element.IntRate;
import com.eugene.element.IrCurve;
import com.eugene.element.MarketVariable;
import com.eugene.entity.MvData;
import com.eugene.entity.Scenario;

public class WriteMvHis {
	private final static Logger logger = LoggerFactory.getLogger(WriteMvHis.class);

	public static void writeMvHis(String mvId, FnCalendar baseDate){
//	public static List<MvData> writeMvHis(String mvId, FnCalendar baseDate){
		List<MarketVariable> marketVariables = new ArrayList<MarketVariable>();
		List<MvData> mvHis = new ArrayList<MvData>();
		MarketVariable marketVari;
		MvData mvData;
		marketVari = MarketVariableDAO.getMarketVariable(mvId, baseDate);
		List<IntRate> intRates = ((IrCurve) marketVari).makeTermStructure(baseDate);
		for (IntRate aa : intRates) {
			mvData = new MvData(aa);
			logger.debug("MvData: {},{}", mvData.getBaseDate(), mvData.getValue());
			MarketVariableDAO.setHistoryData(mvData);
//			mvHis.add(mvData);
		}
//		return mvHis;
	}
	public static void writeSceMvHis(String mvId, String sceId, FnCalendar baseDate){
//	public static List<MvData> writeSceMvHis(String mvId, String sceId, FnCalendar baseDate){
		List<MvData> mvHis = new ArrayList<MvData>();
		Scenario sce = new Scenario();
		
		mvHis =sce.creteScenarioMv(sceId, mvId, baseDate);
		MarketVariableDAO.setSceHistoryData(mvHis);
		
//		return mvHis;
		
	}
	public static void writeSceMvHis(String sceSetId, FnCalendar baseDate){
//	public static List<MvData> writeSceMvHis(String sceSetId, FnCalendar baseDate){
		List<MvData> mvHis = new ArrayList<MvData>();
		Scenario sce = new Scenario();
		
		mvHis =sce.creteScenarioMv(sceSetId, baseDate);
		MarketVariableDAO.setSceHistoryData(mvHis);
		
//		return mvHis;
		
	}
	public static void writeSceMvHisAll(FnCalendar baseDate){
//	public static List<MvData> writeSceMvHisAll(FnCalendar baseDate){
		List<MvData> mvHis = new ArrayList<MvData>();
		Scenario sce = new Scenario();
		List<String> sceSetIds =ScenarioDAO.getScenarioSetIds();
		for(String sceSetId: sceSetIds){
			mvHis =sce.creteScenarioMv(sceSetId, baseDate);
			MarketVariableDAO.setSceHistoryData(mvHis);
		}
		
//		return mvHis;
		
	}
}
